package com.base.cn.platform.os.controller.qa.qaattend;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.entity.qa.qaattend.QaAttend;
import com.base.cn.platform.os.service.qa.qaattend.QaAttendBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * 问答旁听Controller
 * @author LIZHIPENG
 * @since 2018/4/26
 */
@RestController
@RequestMapping("/course")
public class QaAttendController extends BaseController {

    @Autowired
    private QaAttendBiz qaAttendBiz;

    @RequestMapping("/attendCount")
    public BigDecimal attendCount(@RequestBody QaAttend attend){
        return qaAttendBiz.attendCount(attend);
    }

    /**
     * 保存旁听支付添加记录
     * @param qaAttendList
     */
    @RequestMapping("/addAttend")
    public void addAttend(@RequestBody List<QaAttend> qaAttendList){
        qaAttendBiz.addAttend(qaAttendList);
    }

    /**
     * 分页查询问题旁听列表
     * @param currentPage 页码
     * @param pageSize 每页显示条数
     * @param qaAttend 条件
     * @param createUserData 是否设置学员数据：true：是，false：否
     * @return
     */
    @RequestMapping("/findQaAttendListPage")
    public PageInfo<QaAttend> findQaAttendListPage(@RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                                   @RequestParam(value = "pageSize", required = false, defaultValue = "10")int pageSize,
                                                   @RequestBody QaAttend qaAttend,
                                                   @RequestParam("createUserData")boolean createUserData){
        Pagination page = new Pagination();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        return qaAttendBiz.findQaAttendListPage(qaAttend, page, createUserData);
    }

    /**
     * 多条件查询围观列表
     * @param attend 查询条件
     * @param crateUserData 是否设置用户对象
     * @return List<QaAttend>
     */
    @RequestMapping("/findQaAttendList")
    public List<QaAttend> findQaAttendList(@RequestBody QaAttend attend,@RequestParam("crateUserData") boolean crateUserData){
        return qaAttendBiz.findQaAttendList(attend,crateUserData);
    }
}
